package com.weiso.weisophonebook.adapter;

import java.util.List;

import com.weiso.weisophonebook.bean.LinkMan;
import com.weiso.weisophonebook.view.MainGetView;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

public class ViewPagerAdapter extends PagerAdapter{

	Context context;
	List<View> viewlist;
	List<LinkMan> linkmanlist;
    MainGetView maingetview;
	public ViewPagerAdapter(Context context,List<View> viewlist,List<LinkMan> linkmanlist,MainGetView maingetview){
		this.context = context;
		this.viewlist = viewlist;
		this.linkmanlist = linkmanlist;
		this.maingetview = maingetview;
	}
	
	
	public int getCount() {
		
		return viewlist.size();
	}

	public void destroyItem(View container, int position, Object object) {
		((ViewPager) container).removeView((View) object);
	}
	
	 
	public LinkManListAdapter linkmanad;
	
	public Object instantiateItem(ViewGroup container, int position) {
		if(position==0){
			if(linkmanad==null){
				linkmanad= new LinkManListAdapter(context, linkmanlist);
				maingetview.linkmainlv.setAdapter(linkmanad);
			}
		}
		container.addView(viewlist.get(position));
		
		return viewlist.get(position);
	}


	public boolean isViewFromObject(View arg0, Object arg1) {
		
		return arg0 == arg1;
	}


	@Override
	public void notifyDataSetChanged() {
		super.notifyDataSetChanged();
		linkmanad.notifyDataSetChanged();
	}

}
